﻿
$(document).ready(function () {
    var autocomplete = $("#contact").kendoAutoComplete({
        minLength: 1,
        dataTextField: "name",
        filter:"contains",
        headerTemplate: '<div class="dropdown-header k-widget k-header">' +
                '<span>Photo</span>' +
                '<span>Contact info</span>' +
                '<span>Email </span>' +
                '<span>Phone</span>'+
            '</div>',
        template: '<span class="k-state-default" style="background-image: url(\'../Content/Images/nophoto.jpg\')"></span>' +
                  '<span class="k-state-default"><h3>#: data.name #</h3><p>#: data.company #</p></span>' +
                      '<span class="k-state-default"><h3> #: data.email #</h3></span> '+
                         '<span class="k-state-default"><h3> #: data.businessPhone #</h3></span> ',

        dataSource: contactDetails,     
        height: 400,
        select: function (e) {
            debugger;
            window.location.href = "../AddContact/ContactHistory#" + $($(e.item).find('span').get(1)).find('h3').html();
            isGridLoadFirstime = true;
            $('#addcontactGrid').data('kendoGrid').dataSource.read();
            $('#addcontactGrid').data('kendoGrid').refresh();
        },
    }).data("kendoAutoComplete");
});

$(document).ready(function () {
    debugger;
    var autocomplete = $("#company").kendoAutoComplete({
        minLength: 1,
        filter: "contains",
        dataTextField: "name",
        headerTemplate: '<div class="dropdown-header k-widget k-header">' +
                '<span>Company</span>' +
            '</div>',
        template: '<span class="k-state-default"><h3>#: data.name #</h3></span>' ,
        dataSource: lookUpCompanyDetails,
        separator: ", ",
        select: function (e) {
            debugger;
            window.location.href = "../AddCompany/CompanyHistory#" + $($(e.item).find('span')).find('h3').html();
            isGridLoadFirstime = true;
            $('#addcompanyGrid').data('kendoGrid').dataSource.read();
            $('#addcompanyGrid').data('kendoGrid').refresh();
        },
        height: 400
    }).data("kendoAutoComplete");
});


$(document).ready(function () {
    var autocomplete = $("#phone").kendoAutoComplete({
        minLength: 1,
        filter: "contains",
        dataTextField: "phone",
        headerTemplate: '<div class="dropdown-header k-widget k-header">' +
                '<span>Phone</span>' +
            '</div>',
        template: '<span class="k-state-default"><h3>#: data.phone #</h3></span>',
        dataSource: phoneDetails,
        separator: ", ",
        height: 400
       
    }).data("kendoAutoComplete");
});





var contactDetails = new kendo.data.DataSource({
    transport: {
        read: {
            url: "/ScratchPad/GetContactDetail/",
            type: "get",
            contentType: "application/json",
            dataType: "json"
        }
    }
});


var lookUpCompanyDetails = new kendo.data.DataSource({
    transport: {
        read: {
            url: "/ScratchPad/GetLookUpCompanyName/",
            type: "get",
            contentType: "application/json",
            dataType: "json"
        }
    }
});

var phoneDetails = new kendo.data.DataSource({
    transport: {
        read: {
            url: "/ScratchPad/GetPhoneNumbers/",
            type: "get",
            contentType: "application/json",
            dataType: "json"
        }
    }
});






